/*
**********************************
***Datasets for the application***
**********************************
Detailed information on the sources and sample selection is in Section II of Huber (2018, AER). The application uses two proprietary firm-level datasets. The first is a record of German firms' relationship banks from the credit rating agency Creditreform (info@creditreform.com, www.creditreform.de). The second is Dafne by Bureau van Dijk (info@bvdinfo.com, dafne.bvdinfo.com). Other researchers can access the datasets by contacting Creditreform and Bureau van Dijk.
*/


*************************************
***Firm panel variable definitions***
*************************************
label var cb_rel "Dummy for Commerzbank relationship"
label var comp_cb_rel_fract_1 "Leave-out mean of cb_rel at product market level"
label var c_cb_rel_fract_1 "Leave-out mean of cb_rel at county level"

label var cb_rel_error_low "Dummy for Commerzbank relationship (measured with low error)"
label var cb_rel_error_med "Dummy for Commerzbank relationship (measured with medium error)"
label var cb_rel_error_high "Dummy for Commerzbank relationship (measured with high error)"

label var exportquote "Export share"
label var importquote "Import share"
label var lage "Ln(firm age)"
label var ind1 "Industry fixed effect"
label var east "Dummy for former GDR"
label var size_c1 "4 firm size bins"
label var indtype "Industry type: 3==High-innov & tradable; 4==Low-innov & non-tradable; 5==Mid-innov & non-tradable; see Huber (2018, AER)"



*****************
***Regressions***
*****************
global controls i.size_c1 lage i.ind1 exportquote importquote east

***Wrong spillover - competition space (ind and for NT county)***
//Only wrong spillover
quietly reghdfe empl_growth_0812 ${controls} ///
cb_rel comp_cb_rel_fract_1 ///
if sample==1, cluster(firm_county) noabsorb
estimates table, keep(cb_rel comp_cb_rel_fract_1) b t stats(N)
estimates store application_1

//Wrong and correct spillover
quietly reghdfe empl_growth_0812 ${controls} ///
cb_rel comp_cb_rel_fract_1 c_cb_rel_fract_1 ///
if sample==1, cluster(firm_county) noabsorb
estimates table, keep(cb_rel comp_cb_rel_fract_1 c_cb_rel_fract_1) b t stats(N)
estimates store application_2

//Industry heterogeneity with wrong spillover: NT and high innovation
quietly reghdfe empl_growth_0812 ${controls} i.indtype ///
cb_rel comp_cb_rel_fract_1 c_cb_rel_fract_1 ///
if sample==1 & indtype>=3 & indtype<=5, cluster(firm_county) noabsorb
estimates table, keep(cb_rel comp_cb_rel_fract_1 c_cb_rel_fract_1) b t stats(N)
estimates store application_3

//Industry heterogeneity with wrong spillover: Tradable and low innovation
quietly reghdfe empl_growth_0812 ${controls} i.indtype ///
cb_rel comp_cb_rel_fract_1 c_cb_rel_fract_1 ///
if sample==1 & (indtype<3 | indtype>5), cluster(firm_county) noabsorb
estimates table, keep(cb_rel comp_cb_rel_fract_1 c_cb_rel_fract_1) b t stats(N)
estimates store application_4


***Measurement error (ME) - county space***
//Correct model without ME
quietly reghdfe empl_growth_0812 ${controls} ///
cb_rel c_cb_rel_fract_1 ///
if sample==1 & comp_cb_rel_fract_1!=., cluster(firm_county) noabsorb
estimates table, keep(cb_rel c_cb_rel_fract_1) b t stats(N)
estimates store application_5

//Low ME
quietly reghdfe empl_growth_0812 ${controls} ///
cb_rel_error_low c_cb_rel_error_low_fract_1 ///
if sample==1 & comp_cb_rel_fract_1!=., cluster(firm_county) noabsorb
estimates table, keep(cb_rel_error_low c_cb_rel_error_low_fract_1) b t stats(N)
estimates store application_6

//Medium ME
quietly reghdfe empl_growth_0812 ${controls} ///
cb_rel_error_med c_cb_rel_error_med_fract_1 ///
if sample==1 & comp_cb_rel_fract_1!=., cluster(firm_county) noabsorb
estimates table, keep(cb_rel_error_med c_cb_rel_error_med_fract_1) b t stats(N)
estimates store application_7

//High ME
quietly reghdfe empl_growth_0812 ${controls} ///
cb_rel_error_high c_cb_rel_error_high_fract_1 ///
if sample==1 & comp_cb_rel_fract_1!=., cluster(firm_county) noabsorb
estimates table, keep(cb_rel_error_high c_cb_rel_error_high_fract_1) b t stats(N)
estimates store application_8

//Industry heterogeneity with high ME: NT and high innovation
reghdfe empl_growth_0812 ${controls} i.indtype ///
cb_rel_error_high c_cb_rel_error_high_fract_1 ///
if sample==1 & indtype>=3 & indtype<=5 & comp_cb_rel_fract_1!=., cluster(firm_county) noabsorb
estimates table, keep(cb_rel_error_high c_cb_rel_error_high_fract_1) b t stats(N)
estimates store application_9

//Industry heterogeneity with high ME: Tradable and low innovation
reghdfe empl_growth_0812 ${controls} i.indtype ///
cb_rel_error_high c_cb_rel_error_high_fract_1 ///
if sample==1 & (indtype<3 | indtype>5) & comp_cb_rel_fract_1!=., cluster(firm_county) noabsorb
estimates table, keep(cb_rel_error_high c_cb_rel_error_high_fract_1) b t stats(N)
estimates store application_10



************
***Outreg***
************
outreg2 [application_1 application_2 application_3 application_4] ///
using "application_results_two", replace ///
keep(cb_rel comp_cb_rel_fract_1 c_cb_rel_fract_1) nocons ///
title("Table Two Spillovers") label nonotes dec(3) ctitle(" ") word

outreg2 [application_5 application_6 application_7 application_8 application_9 application_10] ///
using "application_results_me", replace ///
keep(cb_rel c_cb_rel_fract_1 ///
cb_rel_error_low c_cb_rel_error_low_fract_1 cb_rel_error_med c_cb_rel_error_med_fract_1 cb_rel_error_high c_cb_rel_error_high_fract_1) nocons ///
title("Table ME") label nonotes dec(3) ctitle(" ") word